package com.qf.bootmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String BOOT_EXCHANGE = "boot_exchange";
    public static final String BOOT_QUEUE = "boot_queue";
    public static final String BOOT_ROUTING_KEY = "#.rabbit";

    //1. 声名boot_exchange，topic类型   <bean id="方法名" class="方法返回结果" />
    @Bean
    public Exchange bootExchange(){
        return ExchangeBuilder.topicExchange(BOOT_EXCHANGE).build();
    }

    //2. 声名boot_queue，
    @Bean
    public Queue bootQueue(){
        return QueueBuilder.durable(BOOT_QUEUE).build();
    }



    //3. 绑定boot_exchange和boot_queue，绑定的routingKey为#.rabbit
    @Bean
    public Binding bootBinding(Queue bootQueue,Exchange bootExchange){
        return BindingBuilder.bind(bootQueue).to(bootExchange).with(BOOT_ROUTING_KEY).noargs();
    }

}
